import React, { useState ,useRef} from 'react';
import { Modal, Button ,Input,Form,Select } from 'antd';
import http from '../../../../services/http';
const { Option } = Select;

export default function Look(props) {
    let form=useRef()
    const [arr, setArr] = useState([])
    const [visible, setVisible] = useState(false);
    const [data,setData] = useState({})
    const [id,setId] = useState('')
    const [address,setAddress] = useState('')

    const edit= (a)=>{
        setId(a.fn.index_id)
        http({    //指标详情pc段
            url:'/getlookindexpcuser',
            data:{
                index_id:a.fn.index_id
            }
          }).then( (res) => {
                console.log(325,res);
                setData(res[0]) 
            form.current.setFieldsValue({
                index_id:res[0].index_id,
                index_name:res[0].index_name,
                index_unit:res[0].index_unit,
                index_up:res[0].index_up,
                index_down:res[0].index_down,
                index_standard:res[0].index_standard,
                org_name:res[0].org_name,
            })
          })
          setVisible(true)
    }

    const onFinish = (values) => {
        console.log('id',parseFloat(values.index_id));
        console.log('name',values.index_name);
        console.log('unit',values.index_unit);
        console.log('up',parseFloat(values.index_up));
        console.log('down',parseFloat(values.index_down));
        console.log('standard',values.index_standard);
        console.log('org',values.org_name);
        http({
            url:'/editindex',
            data:{
                index_id:parseFloat(values.index_id),
                index_name:values.index_name,
                index_unit:values.index_unit,
                index_up:parseFloat(values.index_up),
                index_down:parseFloat(values.index_down),
                index_standard:values.index_standard,
                org_name:values.org_name,
            }
          }).then( (res) => {
            window.location.reload()
        })
    };
    
    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };

    function handleChange(value) {
        console.log('机构', value);
      }

    return (
        <span>
            <a  type="primary" onClick={
                edit.bind(this,props)}
                >
                编辑
            </a>
            <Modal
                className='data' 
                title="编辑"
                centered
                footer={
                    [] // 设置footer为空，去掉 取消 确定默认按钮
                }
                onCancel={() => setVisible(false)}
                visible={visible}>
                    <Form  
                    ref={form}
                    name="basic"
                    labelCol={{ span: 8 }}
                    wrapperCol={{ span: 15 }}
                    initialValues={{ remember: true }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    >
                         <Form.Item
                            label="套餐ID"
                            name="index_id"
                            shouldUpdate
                            rules={[{
                                message: '请输入套餐ID' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input disabled/>
                        </Form.Item>
                        <Form.Item
                            label="机构指标名称"
                            name="index_name"
                            rules={[{
                                message: '请输指标名称',
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="指标单位"
                            name="index_unit"
                            rules={[{
                                message: '请输指标单位' ,
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="参考上限"
                            name="index_up"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="参考下限"
                            name="index_down"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="对应指标标准"
                            name="index_standard"
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="机构名称"
                            name="org_name"
                            rules={[{
                                required: true, 
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item wrapperCol={{ offset: 11, span: 16 }}>
                            <Button onClick={() => setVisible(false)}>
                            取消
                            </Button>

                            <Button type="primary" htmlType="submit" style={{margin:'10px'}} onClick={() => setVisible(false)}>
                            提交
                            </Button>
                        </Form.Item>
                    </Form>
            </Modal>
        </span>
    )
}